NetCloak 2.5 User's Guide

Variable Commands


About Variables

NetCloak supports four distinct types of variables: Local, User, Global, and Cookies. The first three types are stored by NetCloak. Cookies are different from the others in that they are stored at the client, so they will be discussed separately later.

Local variables can be used only within a single HTML page. Local variables can be set at the top of the page and used repeatedly within the page, but once the page has been served completely the variable is forgotten. Local variables are useful for storing data that only needs to be used on another part of the same page, such as in math functions, simplifying complicated SHOW/HIDE expressions, passing variables into macros, etc.

User variables remain in effect for a particular user during the time they are visiting your site. When a form is submitted to NetCloak, the fields on the form become NetCloak user variables automatically. User variables will not affect users other than the user they are set for, but they persist between page accesses, until another form is processed by the same user. User variables are tracked either by the visitor's IP address or by a default cookie that can be generated by NetCloak. Note that when the user does not have a browser which supports cookies, then user variables will be tracked by IP address even if you set the default cookie. See the "SET_COOKIE" command description for information about creating a default cookie.

Global variables are variables that are retained indefinitely and have a single value for all pages being served to all users. You can use globals as "mini-macros", making short blocks of text (a few characters or words) easy to use throughout your site. Global variables also allow you to have the actions taken by one user on your site to impact others. For example, you could have a form that allowed you, as the Webmaster, to turn on and off various portions of your Web site, by showing and hiding links to pages based on global variables that were effected by form submissions. You could also create multi-user games, implement opinion polls, and more.

Global variables can also be viewed and edited using the "Variables" tab of the "Edit Lists..." dialog box of the NetCloak CGI application. This makes using global variables extremely simple and convenient for use as short macros.

Accepting Forms To Set Variables

NetCloak allows you to create HTML forms that ask the user to enter information and then use that information in your pages. The contents of the form are then automatically used to create User Variables.

Each field of your HTML form will have a name. Once the form is submitted, each field becomes a NetCloak User variable with the same name. The variable can then be referenced by name on subsequent pages. You can either show the variables to the user in the text of your HTML document, or use SHOW and HIDE to have your page change based on what the user entered into the fields of the form.

The first step is to create an input form which uses the POST method for form processing. In the ACTION field of your FORM command, you will need to specify the URL of a document that will be processed by NetCloak. NetCloak will store data entered on the form and then serve the file specified. Here is an example of an HTML form:

     <HTML>     <TITLE>Variable Entry Example</TITLE>     <BODY>     <FORM method=POST action="/VarDisplay.html">     Please fill out this simple form...<P>     Name:
     <INPUT TYPE="text" NAME="YourName" SIZE="32" MAXLENGTH="32">     <P>     Organization: 
     <SELECT name="Organization">     <OPTION selected>Commercial
     <OPTION>K12 Education
     <OPTION>Higher Education
     <OPTION>Government
     </SELECT>     <P>     Check here <INPUT NAME="MyCheckBox" TYPE=checkbox VALUE="CHECKED">     <INPUT TYPE=submit VALUE="Submit Form">     <INPUT TYPE=reset VALUE="Start Over">     </BODY>     </HTML>

In this example, the action specified is "/VarDisplay.html", which is simply the name of the html file we would like served when the user clicks the "Submit Form" button. Of course, the page will need to be served by NetCloak, so the file name specified in the action must end with an extension that is mapped to NetCloak. The example assumes that the Web server is configured to cloak all ".html" files.

Once a form has been processed, the fields on the form become User variables that may be used within cloaked documents.

<SET_LOCAL VariableName = Value>
<SET_VARIABLE VariableName = Value>
<SET_GLOBAL VariableName = Value>

Variables can be assigned values either by user input or by using the SET_LOCAL, SET_VARIABLE, or SET_GLOBAL commands. Each of the "SET" commands sets the variable "VariableName" to a given value. The equal sign ("=") is optional. The "Value" can be a string, a number, or another local, user, global, counter or cookie variable (see below for information about cookies). In addition, five operators can currently be used to create a value from an expression. They are:

+Performs simple addition.
-Subtracts the second value from the first.
*Multiplies two values.
/Divides the first value by the second.
&Concatenates two values (Adds the strings).

For example, to put the value of "2 + 2" into the local variable "Four", you could use the command:

     <SET_LOCAL Four = 2 + 2>

Another way to put the number 4 into the variable "Four" would be:

     <SET_LOCAL Two = 2>     <SET_LOCAL Four = Two * 2>

We could also set a variable called "TwentyTwo" by doing something like:

     <SET_LOCAL Two = 2>     <SET_LOCAL TwentyTwo = Two & "2">

It is standard practice to put strings in quotes and leave numeric values without, but NetCloak will accept a number in quotes or a string without. Also, the equal sign is not required, though is encouraged for readability, especially when performing numeric operations.

Remember that when assigning a variable, you can reference any local, user, global, counter, or cookie variable. So, you can set a local variable to the value currently held in a global, or a global variable to the current value of a counter.

For example, let's say you have a counter on your home page called "HomeHits", and another counter on every page of your server called "TotalHits". You could display the percentage of hits your home page receives on your site with something like:

     <SET_LOCAL HHTemp = HomeHits * 100>     <SET_LOCAL Percentage = HHTemp / TotalHits>     Home Page: <INSERT_LOCAL Percentage>%

Note that since NetCloak handles all variables as integers, the HomeHits value must be multiplied by 100 before dividing by the total number of hits.

<INSERT _LOCAL VariableName>
<INSERT _VARIABLE VariableName>
<INSERT _GLOBAL VariableName>

These commands will place the contents of the variable into the page. The value inserted may be a computed variable created using a SET command, or it could be the field from a user-entered form.

For example, after the form above has been filled out and submitted, you could use the following command to display the user's name:

     Your name is: <INSERT_VARIABLE YourName>

Inserted variables will appear as you would expect, with the value of the variable inserted at the point at which the INSERT command is placed. Numeric values will be displayed as numbers (not an ASCII representation of the value) so that a variable with a value of 65 will be displayed as "65" (and not the ASCII letter "A").

Important Note! It is possible for NetCloak to incorrectly identify users and confuse the variables. This can occur when browsers don't support cookies (or are configured not to allow them) and/or when user IP addresses are being dynamically assigned or users connect through a proxy server. For this reason, you should not use User variables to show and hide secure information, or for mission critical applications. In cases where you are certain that each user will have a unique IP address (for example, possibly on your internal LAN) User variables will be reliable.

Note that expressions used to create values for variables ("+", "-", etc.) cannot be used in INSERT commands. To display a computed value, you must SET a variable first then reference it by name in the INSERT command.

<HIDE_LOCAL VariableName Value1 Value2 ...>
<HIDE_VARIABLE VariableName Value1 Value2 ...>
<HIDE_GLOBAL VariableName Value1 Value2 ...>

Any HTML text that follows HIDE_LOCAL, HIDE_VARIABLE, or HIDE_GLOBAL will be hidden from those users when the specified variable contains the specified text. An example should make this more clear. Assuming that the input form above has been filled out and submitted by the user, we could use:

     <SHOW>     <HIDE_VARIABLE YourName "J">     Your name does not contain a J.
     <SHOW>

Here, the variable YourName (what the user entered into the field "YourName" on the input form) is checked to see if it contains a "J". If it does, text will be hidden, and the phrase "Your name does not contain a J" will not be seen. To see if the checkbox was checked, we could use:

     <SHOW>     <HIDE_VARIABLE MyCheckBox "CHECKED">     You didn't check the check box!

Frequently, it is necessary to check that a variable value is not empty, as when a user is filling out form fields. You can check for non-empty variables by simply not specifying a value in the HIDE command. For example:

     <SHOW>     <HIDE_VARIABLE YourName>     You didn't enter a name!
     <SHOW>

The text "You didn't enter a name!" will only appear if the "YourName" field was left blank in the form.

<SHOW_LOCAL VariableName Value1 Value2 ...>
<SHOW_VARIABLE VariableName Value1 Value2 ...>
<SHOW_GLOBAL VariableName Value1 Value2 ...>

This command operates exactly like HIDE_VARIABLE except that is turns the text stream on instead of turning it off. To continue the example from above, we could also show a message when the checkbox is checked, by using:

     <HIDE>     <SHOW_VARIABLE MyCheckBox "CHECKED">     You checked the check box!
     <SHOW>


[ Command Listing | Table Of Contents ]

Copyright © 1996-7 Maxum Development Corporation
820 South Bartlett Road - Suite 104
Streamwood, IL 60107
http://www.maxum.com/